import React from "react";
import { Row, Col, Button, PageHeader, Breadcrumb,message,Spin } from "antd";
import { EditFilled } from "@ant-design/icons";
import { Link } from "react-router-dom";

import BraftEditor from "braft-editor";
import "braft-editor/dist/index.css";
import { _getTchIntro, _updateTchIntro } from "../../util/api/user/index";
class AddArticle extends React.Component {
  state = {
    editorState: BraftEditor.createEditorState(null),
    isLoading:false
  };

  componentDidMount =() => {
    this.setState({ isLoading: true });
    _getTchIntro()
      .then((res) => {
        console.log(res.data);
        this.setState({ isLoading: false });
        if (res.status === 200 && res.data.code === 0) {
          let htmlContent = res.data.data[0].t_detail;
          localStorage.setItem('t_intro',htmlContent)
          this.setState({
            editorState: BraftEditor.createEditorState(htmlContent),
          });
        }
      })
      .catch((err) => {
        this.setState({ isLoading: false });
        console.log(err);
        message.error("服务器错误");
      });
  }

  render() {
    const { editorState } = this.state;
    const excludeControls = [
      "undo",
      "redo",
      "separator",
      "font-size",
      "line-height",
      "letter-spacing",
      "separator",
      "text-color",
      "bold",
      "italic",
      "underline",
      "strike-through",
      "separator",
      "superscript",
      "subscript",
      "remove-styles",
      "emoji",
      "separator",
      "text-indent",
      "text-align",
      "separator",
      "headings",
      "list-ul",
      "list-ol",
      "blockquote",
      "code",
      "separator",
      "link",
      "separator",
      "hr",
      "separator",
      "media",
      "separator",
      "clear",
      "fullscreen",
    ];

    return (
      <div>
        <Row justify="end">
          <Col span={24}>
            <PageHeader
              ghost={false}
              subTitle="老师主页"
              extra={[
                <Link to="/m/member/t/e">
                  <Button type="primary" block icon={<EditFilled />}>
                    编辑
                  </Button>
                </Link>,
              ]}
            ></PageHeader>
          </Col>
        </Row>
        <br />
        <Row>
          <Col span={24}>
            <Spin tip="Loading..." spinning={this.state.isLoading}>
              <BraftEditor
                value={editorState}
                excludeControls={excludeControls}
                readOnly={true}
              />
            </Spin>
          </Col>
        </Row>
      </div>
    );
  }
}

export default AddArticle;
